<template>
  <section class="room">
    <headerUtil :obj="headerObj">直播间列表</headerUtil>
    <div class="content" @scroll.passive="scrollData" ref="scrollOut">
      <div class="list">
        <div class="livingRoom" @click="intolivingRoom(item)" v-for="(item, index) in list" :key="index">
          <div class="roomImg" :style="{background: `url(${item.covertImg}) no-repeat center`}"></div>
          <div class="roomId">{{item.id}}</div>
          <div class="roomName">{{item.roomName}}</div>
        </div>

      </div>
    </div>
    <!-- <commonNavUtil :iNow="5"></commonNavUtil> -->
  </section>
</template>
<script>
import reqApis from "../../req/reqApis.js";
import headerUtil from "../base/common/headerUtil.vue";

export default {
  components: {
    headerUtil
  },
  data () {
    return {
      roomType: this.$route.query.roomType || 1,
      user: {

      },
      headerObj:{
        showType: 2
      },
      list: [],
      pageIndex: 1,
      isStop: false
    }
  },
  created() {
    
    reqApis.getLivingListApi({page: 1, pageSize:10, type: this.roomType}).then(res => {
      this.list = res.data.list;
    }).catch(err => {
      console.log(err)
    })
    // this.getUserFn();
  },
  methods: {
    intolivingRoom(item) {
      if(this.roomType == 1) {
        this.$router.push({path: "/livingRoom", query: {roomId: item.id}})
      }else if (this.roomType == 2) {
        this.$router.push({path: "/pkLivingRoom", query: {roomId: item.id}})
      }
      
    },
    scrollData() {
      let outH = this.$refs.scrollOut.scrollHeight,
          currentH = this.$refs.scrollOut.offsetHeight,
          offH = this.$refs.scrollOut.scrollTop;
        if(currentH + offH >= (outH-1)){
          this.pageIndex += 1;
        }
    },
    // startingLivingFn(type){
    //   reqApis.startingLivingApi({type:type}).then(res => {
    //       console.log(res)
    //     }).catch(err => {
    //         console.log(err)
    //     })
    // },
    // getUserFn(){
    //   reqApis.initPageApi({}).then(res => {
    //           this.user = res.data;
    //         }).catch(err => {
    //             console.log(err)
    //         })
    //   // reqApis.getUserFn({}).then(res => {
    //   //   this.user = res.data;
    //   // })
    // },
  }
}
</script>
<style lang="less" scoped>
.room {
  width: 3.75rem;
  height: 100%;
  display: flex;
  flex-direction: column;
  .content {
    flex: 1;
    overflow-y: auto;
    .list {
      overflow: hidden;
      padding: 0.05rem;
      .livingRoom {
        width: 1.8rem;
        margin-bottom: 0.05rem;
        background: white;
        float: left;
        .roomImg {
          width: 100%;
          height: 1.8rem;
        }
        .roomName {
          padding: 0.1rem 0.01rem;
          font-size: 0.14rem;
          color: #333;
        }
        &:nth-of-type(2n) {
          float: right;
        }
        
      }
      
    }
  }
}
</style>

